//
//  BKMyOrderRetuanGoodDetailController.m
//  bestkeep
//
//  Created by Mr. Wu on 16/12/19.
//  Copyright © 2016年 utouu. All rights reserved.
//

#import "BKMyOrderRetuanGoodDetailController.h"
#import "HeadView.h"
#import "BKMyOrderBackGoodsCell.h"

#import "BKMyOrderWebViewController.h"
#import "BKMyOrderReturnGoodsModel.h"
#import "BKMyOrderReturnGoodsProgressController.h"
#import "BKMyOrderApplyToReturnGoodsControllerViewController.h"

#import "BK_OD_Tool.h"
#import "BK_OD_Color.h"

@interface BKMyOrderRetuanGoodDetailController ()
@property (nonatomic,strong)NSString* pape_no;//页数
@property(nonatomic,strong)NSString *total;
@property (nonatomic,strong)NSMutableArray *arr;
@property (nonatomic,strong)NSMutableArray *muArr;
@property (nonatomic , strong)NSArray *dataArr;
@end

@implementation BKMyOrderRetuanGoodDetailController
-(NSMutableArray *)muArr{
    if (!_muArr ) {
        _muArr = [NSMutableArray array];
        
    }return _muArr;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.title =@"退换货商品列表";
    _pape_no =@"1";
    self.view.backgroundColor =RGB(234, 234, 234);
    [self initView];
    self.edgesForExtendedLayout = UIRectEdgeNone;
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
   }
-(void)initView{
    _bottomView =[UIView new];
    _bottomView.backgroundColor = kOrderBKGreen;
    [self.view addSubview:_bottomView];
    [_bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view.mas_left);
        make.right.equalTo(self.view.mas_right);
        make.bottom.equalTo(self.view.mas_bottom);
        make.height.equalTo(@(50));
    }];
    _applytableview =[[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStyleGrouped];
    _applytableview.separatorColor = [UIColor whiteColor];
    _applytableview.delegate = self;
    _applytableview.dataSource = self;
    _applytableview.sectionFooterHeight = 5;
    _applytableview.backgroundColor =RGB(242, 242, 242);
    [_applytableview registerClass:[BKMyOrderBackGoodsCell class] forCellReuseIdentifier:@"backcell"];
    [self.view addSubview:_applytableview];
    [_applytableview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view.mas_left);
        make.right.equalTo(self.view.mas_right);
        make.top.equalTo(self.view.mas_top).offset(10);
        make.bottom.equalTo(_bottomView.mas_top).offset(0);
    }];
    UIView *lien =[UIView new];
    lien.backgroundColor =kOrderBKGreen;
    [_bottomView addSubview:lien];
    [lien mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(@(2));
        make.centerY.equalTo(_bottomView.mas_centerY);
        make.centerX.equalTo(_bottomView.mas_centerX);
        make.height.equalTo(@(50));
    }];
    _titleBtn =[UIButton new];
    [_titleBtn setTitle:@"退换货进度查询" forState:(UIControlStateNormal)];
    [_titleBtn setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
    [_titleBtn addTarget:self action:@selector(titleBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    [_bottomView addSubview:_titleBtn];
    [_titleBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_bottomView.mas_left);
        make.top.equalTo(_bottomView.mas_top);
        make.bottom.equalTo(_bottomView.mas_bottom);
        make.right.equalTo(lien.mas_left);
    }];
    _ingApply = [UIButton new];
    [_ingApply setTitle:@"退换货说明" forState:(UIControlStateNormal)];
    [_ingApply setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
    [_ingApply addTarget:self action:@selector(ingApplyAction:) forControlEvents:UIControlEventTouchUpInside];
    [_bottomView addSubview:_ingApply];
    [_ingApply mas_makeConstraints:^(MASConstraintMaker *make){
        make.left.equalTo(lien.mas_right);
        make.right.equalTo(_bottomView.mas_right);
        make.top.equalTo(_bottomView.mas_top);
        make.bottom.equalTo(_bottomView.mas_bottom);
    }];
    
 
}


//退换货进度查询
-(void)titleBtnAction:(UIButton *)button{
    BKMyOrderReturnGoodsProgressController*queryVC = [[BKMyOrderReturnGoodsProgressController alloc]init];
    [self.navigationController pushViewController:queryVC animated:YES];
}
//退换货说明
-(void)ingApplyAction:(UIButton *)btn{
    NSString *reqset =@"http://cdn.bestkeep.cn/ui/pc/agreement/returngoods-agreement.html";
    BKMyOrderWebViewController *ucWK = [[BKMyOrderWebViewController alloc] init];
    ucWK.webViewUrl = reqset;
    ucWK.webViewTitle =@"退换货说明";
    [self.navigationController pushViewController:ucWK animated:YES];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
  
     return  self.orderModel.item_list.count;
    }

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 85;
}

- (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    HeadView *headView = [[HeadView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 40)];
    headView.backgroundColor = [UIColor whiteColor];
      headView.orderModel = self.orderModel;
        return headView;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
        return 110;
    
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
        BKMyOrderBackGoodsCell *cell = [tableView dequeueReusableCellWithIdentifier:@"backcell" forIndexPath:indexPath];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
                  cell.ordermodel = self.orderModel.item_list[indexPath.row];
        [cell.backButton addTarget: self action:@selector(action_btn:) forControlEvents:UIControlEventTouchUpInside];
        return cell;
    
    
    
}
#pragma  mark---申请退换货   点击事件
-(void)action_btn:(UIButton *)button{
    
    BKMyOrderBackGoodsCell *cell;
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0 ) {
        cell =(BKMyOrderBackGoodsCell *)[button superview].nextResponder;
        
    }else {
        cell = (BKMyOrderBackGoodsCell*)button.superview.superview.superview;
        
    }
    
    BKMyOrderApplyToReturnGoodsControllerViewController *applyVC = [[ BKMyOrderApplyToReturnGoodsControllerViewController alloc]init];
     applyVC.OrderModel =cell.ordermodel;
    
       [self.navigationController pushViewController:applyVC animated:YES];
}




@end
